package com.pointmi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import com.pointmi.customeraccountdao.Customer;
import com.pointmi.customeraccountservice.CustomerAccountService;

@Controller
@RequestMapping("/pointmi-api/auth")
public class CustomerAccountController {
	
	@Autowired
	@Qualifier("customerService")
	private CustomerAccountService customerAccountService;
	
	@RequestMapping(value = "/customer/{email}/{password}", method = RequestMethod.POST)
	@ResponseBody
	public Customer login(@PathVariable("email") String email, @PathVariable("password") String password)
	{
		return customerAccountService.findCustomerByEmailAndPassword(email, password);
	}
	
	@RequestMapping(value = "/register", method = RequestMethod.POST)
	@ResponseStatus( HttpStatus.CREATED )
	public void save(@RequestBody Customer newCustomer)
	{
	  customerAccountService.saveOrUpdate(newCustomer);
	}
	
	@RequestMapping(value="/accountsummary/{customerId}/{email}")
	@ResponseStatus( HttpStatus.OK)
	@ResponseBody
	public Customer accountSummary(@PathVariable("email")String email, @PathVariable("customerId") String customerId)
	{
		return customerAccountService.findCustomerByEmailOrCustomerId(email, customerId);
	}

}
